// pages/notice/notice.js
const app =getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        notices:[],
        applyUserName:'Kinnon'
    },
    
    getNotice:function(){
        var that = this
        wx.request({
          url: app.globalData.requestContext + '/getNotices',
          method:'GET',
          success:function(res){
              if(res.data.code == 0){
                that.setData({
                    notices: res.data.data
                })
              }
           
          }
        })
    },
    agreeApply:function(e){
        var that = this
        var userId = e.currentTarget.dataset.userid
        wx.showModal({
          cancelColor: 'cancelColor',
          title:'提示',
          content:'是否确认同意？',
          success (res) {
            if (res.confirm) {
                wx.request({
                    url: app.globalData.requestContext + '/agreeApply',
                    method:'post',
                    data:{
                      userId:parseInt(userId)
                    },
                    header:{
                      'content-type': "application/x-www-form-urlencoded" ,// 默认值
                      'token': wx.getStorageSync("token")
                    },
                    success:function(res){
                        if(res.data.code == 0){
                          wx.showToast({
                            title: res.data.msg,
                            icon:'success',
                            duration:2000
                          })
                          
                        }else if(res.data.code == 1){
                          wx.showToast({
                              title: res.data.msg,
                              icon:'none'
                            })
                           
                        }else{
                          wx.showToast({
                              title: res.data.msg,
                              icon:'none'
                            })
                        }
                    },
                    complete:function(res){
                      that.getNotice()
                    }
                  })
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
       
    },
    disagreeApply:function(e){
        var that = this
        var userId = e.currentTarget.dataset.userid
        wx.showModal({
            title: '提示',
            content: '是否确认拒绝',
            success (res) {
              if (res.confirm) {
                wx.request({
                    url: app.globalData.requestContext + '/disAgreeApply',
                    method:'post',
                    data:{
                      userId:parseInt(userId)
                    },
                    header:{
                      'content-type': "application/x-www-form-urlencoded" ,// 默认值
                      'token': wx.getStorageSync("token")
                    },
                    success:function(res){
                        if(res.data.code == 0){
                            if(res.data.code == 0){
                                wx.showToast({
                                  title: res.data.msg,
                                  icon:'success',
                                  duration:2000
                                })
                            }
                        }else if(res.data.code == 1){
                            if(res.data.code == 0){
                                wx.showToast({
                                  title: res.data.msg,
                                  icon:'none',
                                  duration:2000
                                })
                            }
                        }else{
                            if(res.data.code == 0){
                                wx.showToast({
                                  title: res.data.msg,
                                  icon:'none',
                                  duration:2000
                                })
                            }
                        }
                     
                    }
                  })
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            },
            complete:function(res){
                that.getNotice()
            }
          })
        
    },
    

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getNotice()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})